package com.xique.park.controller.auto;

import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.bean.domain.BaseUser;
import com.xique.park.service.service.IBaseUserService;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.utils.poi.ExcelUtil;
import com.xique.common.core.web.page.TableDataInfo;

/**
 * 用户Controller
 * 
 * @author caogq
 * @date 2021-12-14
 */
@RestController
@RequestMapping("/baseUser")
public class BaseUserController extends BaseController
{
    @Autowired
    private IBaseUserService baseUserService;

    /**
     * 查询用户列表
     */
    @PreAuthorize(hasPermi = "system:baseUser:list")
    @GetMapping("/list")
    public TableDataInfo list(BaseUser baseUser)
    {
        startPage();
        List<BaseUser> list = baseUserService.selectBaseUserList(baseUser);
        return getDataTable(list);
    }

    /**
     * 导出用户列表
     */
    @PreAuthorize(hasPermi = "system:baseUser:export")
    @Log(title = "用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseUser baseUser) throws IOException
    {
        List<BaseUser> list = baseUserService.selectBaseUserList(baseUser);
        ExcelUtil<BaseUser> util = new ExcelUtil<BaseUser>(BaseUser.class);
        util.exportExcel(response, list, "用户数据");
    }

    /**
     * 获取用户详细信息
     */
    @PreAuthorize(hasPermi = "system:baseUser:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(baseUserService.selectBaseUserById(id));
    }

    /**
     * 新增用户
     */
    @PreAuthorize(hasPermi = "system:baseUser:add")
    @Log(title = "用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BaseUser baseUser)
    {
        return toAjax(baseUserService.insertBaseUser(baseUser));
    }

    /**
     * 修改用户
     */
    @PreAuthorize(hasPermi = "system:baseUser:edit")
    @Log(title = "用户", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody BaseUser baseUser)
    {
        return toAjax(baseUserService.updateBaseUser(baseUser));
    }

    /**
     * 删除用户
     */
    @PreAuthorize(hasPermi = "system:baseUser:remove")
    @Log(title = "用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        List<Long> idsList = Arrays.asList(ids);
        return toAjax(baseUserService.deleteBaseUserByIds(idsList));
    }
}
